package com.liser.southernstar.collection.ui.adapter;


import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.liser.southernstar.R;
import com.liser.southernstar.collection.model.vo.OrderItemVO;
import com.liser.southernstar.neleme.views.AddGoodsWidget;

import java.util.List;

public class OrderItemAdapter extends BaseQuickAdapter<OrderItemVO, BaseViewHolder> {

    public static final int FIRST_STICKY_VIEW = 1;

    public static final int HAS_STICKY_VIEW = 2;

    public static final int NONE_STICKY_VIEW = 3;

    private List<OrderItemVO> orderItemVOList;

    private AddGoodsWidget.OnAddClick onAddClick;

    public OrderItemAdapter() {
        super(R.layout.adapter_order_item);
    }

    public OrderItemAdapter(@Nullable List<OrderItemVO> data) {
        super(R.layout.adapter_order_item, data);
        orderItemVOList = data;
    }

    public void setOnAddClick(AddGoodsWidget.OnAddClick onAddClick) {
        this.onAddClick = onAddClick;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderItemVO item) {
        helper.setText(R.id.tv_goods_name, item.getGenre_name())
                .setText(R.id.tv_goods_detail, item.getDescribe())
//                .setText(R.id.tv_sale, "月售2")
                .setText(R.id.tv_goods_price, item.getStrPrice(mContext))
                .addOnClickListener(R.id.addwidget)
                .addOnClickListener(R.id.food_main);
        // 设置图片
        ImageView view = helper.getView(R.id.iv_goods_img);
        Glide.with(mContext)
                .load(item.getMain_img())
                .into(view);
        AddGoodsWidget addGoodsWidget = helper.getView(R.id.addwidget);
        addGoodsWidget.setData(onAddClick, item);

        if (helper.getAdapterPosition() == 0) {
            helper.setVisible(R.id.stick_header, true)
                    .setText(R.id.tv_header, item.getGenre_name())
                    .setTag(R.id.food_main, FIRST_STICKY_VIEW);
        } else {
            /*if (!TextUtils.equals(item.getName(), orderItemVOList.get(helper.getAdapterPosition() - 1).getName())) {
                helper.setVisible(R.id.stick_header, true)
                        .setText(R.id.tv_header, item.getGenre_name())
                        .setTag(R.id.food_main, HAS_STICKY_VIEW);
            } else {
                helper.setVisible(R.id.stick_header, false)
                        .setTag(R.id.food_main, NONE_STICKY_VIEW);
            }*/
        }
        helper.getConvertView().setContentDescription(item.getGenre_name());
    }

}
